package superbubble.onegraph;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import superbubble.entry.Graph;
import superbubble.entry.Edge;
import superbubble.entry.StrongConnectedComponent;
import superbubble.file.ReadFromFile;

public class OneGraph {
	private List<StrongConnectedComponent> listSCC;

	public OneGraph() {
		super();
	}

	public Graph convertGraphToOneGraph(Graph graph) {
		Graph oneGraph = graph;
		
		for (StrongConnectedComponent scc : listSCC) {
			Random generator = new Random();
			int randomIndex = generator.nextInt(scc.getNodes().size());
			Edge newLink = new Edge(0, randomIndex, 1);
			oneGraph.addNewLink(newLink);
		}
		System.out.println();
		return oneGraph;
	}

	public void creatSCCList() {
		
		byte matrix[][] = ReadFromFile.readMatrixFromFile("input_graph.txt");
		StrongConnectedComponentsFinder strong = new StrongConnectedComponentsFinder(
				ReadFromFile.getNumberNodes());
		strong.strongConnectedComponent(matrix);
		listSCC = new ArrayList<>();
		for (int i = 1; i < strong.getLeader_node().length; i++) {
			int idForCurrentSCC = strong.getFinishing_time_map().get(
					strong.getLeader_node()[i]);
			StrongConnectedComponent scc = new StrongConnectedComponent();
			scc.setComponentId(idForCurrentSCC);
			if (listSCC.contains(scc)) {
				listSCC.get(listSCC.indexOf(scc)).addNodeToComponent(i);
			} else {
				scc.addNodeToComponent(i);
				listSCC.add(scc);
			}
		}
		for (int i = 0; i < listSCC.size(); i++) {
			System.out.println(listSCC.get(i).toString());
		}
	}

}
